﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using PPI.Entities.Interface;
using PPI.Mobile;
using VMind.Global;


namespace PPI.ServiceLogic.Distribution
{
    public class LLength : IMobileTable
    {
        public static DataSet SelectAllIdName(string connectionKey)
        {
            return PPIDataAccess.Distribution.DLength.SelectAll(connectionKey);
        }

        public List<EMobileQuery> CreateInsertMobileQuery(string connectionKey)
        {
            DataTable lengths = PPIDataAccess.Distribution.DLength.SelectAll(connectionKey).Tables[0];

            List<EMobileQuery> listQueries = new List<EMobileQuery>();
            listQueries.Add(new EMobileQuery(string.Format("DELETE tb_Lookups WHERE LookupTypeFk = '{0}'", "Length")));

            EMobileQuery insertQuery = new EMobileQuery("INSERT INTO tb_Lookups (LookupValue, LookupText, LookupTypeFk) VALUES (@id, @Name, 'Length')");

            foreach (DataRow length in lengths.Rows)
            {
                List<SqlParameter> parameters = new List<SqlParameter>();

                parameters.Add(DBHelper.CreateIntParameter("@id", ParameterDirection.Input, false, Convert.ToInt32(length["LengthId"])));
                parameters.Add(DBHelper.CreateNVarCharParameter("@Name", 100, ParameterDirection.Input, false, length["Name"]));

                insertQuery.Parameters.Add(parameters);
            }

            listQueries.Add(insertQuery);
            
            return listQueries;
        }
    }
}
